<?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php
if (isset($_SESSION['lang']))
    require_once "./language_files/conferenceSetup_" . $_SESSION['lang'] . ".php";
else
    require_once "./language_files/conferenceSetup_en.php";
?>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <meta http-equiv="X-UA-Compatible" content="IE=9" />
        <link rel="stylesheet" type="text/css" href="style3.css"/>
        <link href="jquery-ui-all.css" rel="stylesheet" type="text/css" />
        <?php include "jquery.php"; ?>
        <script type="text/javascript" src="functions.js"></script>
        <script type="text/javascript" src="jquery-accordion.js"></script>
        <script type="text/javascript" src="jquery-ui-1.8.21.custom.min.js"></script>

        <script type="text/javascript">
            //<![CDATA[
            function validateDate(datestring)
            {
                if(datestring==undefined)
                    return false;
                regexp=/^20(1[0-9]|2[0-9]|3[0-8])(-|\/)\d{2}(-|\/)\d{2}$/;
                if(datestring.match(regexp)==null)
                    return false;
                else
                    return true;
            }
            //]]>
        </script>
        <script type="text/javascript">
            //<![CDATA[
            $(function() {
                $( "#review_end_date" ).datepicker({ dateFormat: "yy-mm-dd" });
                $( "#postersubmissiondate" ).datepicker({ dateFormat: "yy-mm-dd" });
                $( "#imagesubmissiondate" ).datepicker({ dateFormat: "yy-mm-dd" });
                $( "#videosubmissiondate" ).datepicker({ dateFormat: "yy-mm-dd" });
                $( "#longpapersubmissiondate" ).datepicker({ dateFormat: "yy-mm-dd" });
                $( "#shortpapersubmissiondate" ).datepicker({ dateFormat: "yy-mm-dd" });
                $( "#rebuttal_date" ).datepicker({ dateFormat: "yy-mm-dd" });
            });
            // wait for the document to be ready before starting the script
            $(document).ready(function(){
                check_top();
                resize_iframe();
                $(function() {
                    $("#accordion").accordion({autoHeight:false, collapsible: true, navigation: true,
                        clearStyle: true,
                        change: function(event, ui) {
                            resize_iframe();
                        }
                    });
                });
                $("#gs").live("click",function(){
                    $('#accordion').accordion('activate', "#deadlines");
                });
                $("#dl").live("click",function(){
                    $('#accordion').accordion('activate', "#reviewprocess");
                });
                $("#prev-deadlines").live("click",function(){
                    $('#accordion').accordion('activate', "#generalSetup");
                });
                $("#prev-reviewprocess").live("click",function(){
                    $('#accordion').accordion('activate', "#deadlines");
                });
                $("#description").bind("keyup input paste",function()
                {
                    len=$("#description").val().length;
                    if(len>2000)
                    {
                        $("#description").val($("#description").val().substr(0,2000));
                    }
                    $("#description_label").html(2000-len);
                });
                $("#call_papers").bind("keyup input paster",function()
                {
                    len=$("#call_papers").val().length;
                    if(len>200)
                    {
                        $("#call_papers").val($("#call_papers").val().substr(0,200));
                    }
                    $("#call_papers_label").html(200-len);
                });
                $("#LongName").bind("keyup input paste",function()
                {
                    len=$("#LongName").val().length;
                    if(len>500)
                    {
                        $("#LongName").val($("#LongName").val().substr(0,500));
                    }
                    $("#long_name_label").html(500-len);
                });
                $("#ShortName").bind("keyup input paste",function()
                {
                    len=$("#ShortName").val().length;
                    if(len>50)
                    {
                        $("#ShortName").val($("#ShortName").val().substr(0,50));
                    }
                    $("#short_name_label").html(50-len);
                });

                $("#custom_committee").bind("change",function()
                {
                    if($(this).is(":checked"))
                        $("#custom_text").removeAttr("disabled");
                    else
                        $("#custom_text").attr("disabled","disabled");
                });
                $("#Submitbutton").bind("click",function(){
                    // stores the string from the text area and stores it in a new variable
                    $(".error").html("");
                    rebuttaldate = $("#rebuttal_date").val(); // new contains the date value to be inserted
                    is_rebuttal = $("#rebuttal_check").val(); // contains value 1 or 0 indicating if the checkbox checked or not,
                    //if 1 insert date into rebuttal_date fel db else do not force user to add date cuz it is optional
                    longname = $("#LongName").val();
                    shortname = $("#ShortName").val();
                    textareadescription = $("#description").val();
                    call_papers_text=$("#call_papers").val();
                    //check if the checkbox is checked , and returns either true (in case checkbox checked  )else it returns false
                    rev_end=$("#review_end_date").val();
                    spapersub = $("#shortpapersubmissiondate").val();
                    lpapersub=$("#longpapersubmissiondate").val();
                    isub=$("#imagesubmissiondate").val();
                    vsub=$("#videosubmissiondate").val();
                    psub=$("#postersubmissiondate").val();
                    //check if the checkbox is checked , it returns either true or false
                    com1 = $("#committe1checkbox").is(":checked");
                    com2 = $("#committe2checkbox").is(":checked");
                    com3 = $("#committe3checkbox").is(":checked");
                    custom_com=$("#custom_committee").is(":checked");
                    customcomtext=$("#custom_text").val();
                    papertype =$("#papertypes").val();
                    conference =$("#previousconf").val();
                    place=$("#place").val();
                    curdate=new Date();
                    rev_end_date=new Date(rev_end);
                    spaper_date=new Date(spapersub);
                    lpaper_date=new Date(lpapersub);
                    poster_date=new Date(psub);
                    image_date=new Date(isub);
                    video_date=new Date(vsub);
                    if (longname == "" || shortname == "" || place == "")
                    {
                        alert("place make sure that you entered the long conference name or the short conference name or place successfully");
                    }
                    else if(spapersub == "" &&  lpapersub == "" && isub == "" && vsub == "" && psub == "") {
                        alert("You have to choose at least one submission type");
                    }
                    if(spapersub != "")
                    {
                        if(!validateDate(spapersub) || spaper_date<=curdate ) {
                            $("#short_paper_label").html("<?php echo $lang['message_3']; ?>");
                        }
                    }
                    if(lpapersub != "")
                    {
                        if (!validateDate(lpapersub) || lpaper_date<=curdate ) {
                            $("#long_paper_label").html("<?php echo $lang['message_3']; ?>");
                        }
                    }
                    if(isub != "")
                    {
                        if (!validateDate(isub) || image_date<=curdate ) {
                            $("#image_label").html("<?php echo $lang['message_3']; ?>");
                        }
                    }
                    if(psub != "")
                    {
                        if (!validateDate(psub) || poster_date<=curdate ) {
                            $("#poster_label").html("<?php echo $lang['message_3']; ?>");
                        }
                    }
                    if(vsub != "")
                    {
                        if (!validateDate(vsub) || video_date<=curdate ) {
                            $("#video_label").html("<?php echo $lang['message_3']; ?>");
                        }

                    }
                    
                    if(!validateDate(rev_end)  || rev_end_date<=curdate)
                    {
                        $("#review_end_label").html("<?php echo $lang['message_2']; ?>");
                    }
                    else if (com1 == false && com2 == false && com3 == false && custom_com == false)
                    {
                        alert("please make sure that you chose at least one committee");
                    }
                    else
                    {
                        $.post("conferenceSetupServerSide.php",{rebuttaldate: rebuttaldate, longname: longname , shortname: shortname ,place:place, textarea: textareadescription,call_papers:call_papers_text ,review_end:rev_end, spapersub: spapersub,lpapersub:lpapersub,imagesub:isub,videosub:vsub,postersub:psub ,comm1: com1 , comm2: com2 , comm3: com3 ,custom_com: custom_com,custom_com_text:customcomtext, papertype: papertype , conference_id: conference},function(data)  //sending all the page values to the server while storing them in new variables
                        {
                            // this checks that if there are any errors that were found then it should be alerted and the function stops. Else there are no errors in the data will be alerted then it will direct the user to the main menu.
                            if(data.indexOf("ERROR CODE:")!=-1)
                            {
                                alert(data);
                            }
                            else
                            {
                                var frame = top.document.getElementById("collabsoft");
                                alert("Process has completed successfully");
                                $(frame).attr("src","conferencePage2.php?conference_id="+data);
                            }
                        });
                    }
                });
            });
            //]]>
        </script>
        <title> <?php echo $lang['title']; ?></title>
    </head>
    <body>
        <!-- created a legend in order to have all the labels and buttons stored in an organized shape  -->
        <!-- created a label followed b a text area in order for the member to enter the specified data  -->
        <h2><?php echo $lang['title']; ?></h2>
           
        <div id="accordion">
            <h3 id="generalSetup"><a href="#">General Setup</a></h3>
            <div>
                <table>

                    <tr>
                        <td><b><?php echo $lang['L_name']; ?></b></td>
                        <td><textarea rows="5" cols="50" id="LongName"></textarea><label id="long_name_label">500</label></td>
                    </tr>
                    <tr>
                        <td><b><?php echo $lang['S_name']; ?></b></td>
                        <td><input type="text" size="50" id="ShortName" /><label id="short_name_label">50</label></td>
                    </tr>
                    <tr>
                        <td><b><?php echo $lang['description']; ?></b></td>
                        <td><textarea rows="5" cols="50" id="description"></textarea><label id="description_label">2000</label></td>
                    </tr>
                    <tr>
                        <td><b><?php echo $lang['callforPapers']; ?></b></td>
                        <td><textarea rows="3" cols="50" id="call_papers"></textarea><label id="call_papers_label">200</label></td>
                    </tr>
                    <tr>
                        <td><b><?php echo $lang['scientificArea']; ?></b></td>
                        <td>    <select id="papertypes">
                                <optgroup label="Paper types">
                                    <?php
                                    include "statics.php";
                                    $query = rsSelect("area_of_expertise_text", "area_of_expertise", NULL, "ORDER BY area_of_expertise_text");  //  getting all area of expertis from database and assgning them in a new value
                                    if (is_string($query)) {
                                        echo $query . "ERROR CODE: 0" . __LINE__;
                                        exit();
                                    }
                                    // fetching  the area of expertise  and insert it in a row then i echo each new row n a seperate line
                                    while ($row = mysql_fetch_assoc($query)) {
                                        echo "<option>" . $row["area_of_expertise_text"] . "</option>";
                                    }
                                    ?>
                                </optgroup>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td><b><?php echo $lang['linkToPrev']; ?></b></td>
                        <td>
                            <select id="previousconf">
                                <optgroup label="previous conferences">
                                    <option value="0" selected="selected"><?php echo $lang['none']; ?></option>
                                    <?php
                                    include "statics.php";
// getting all the names of the created conferences that were stored in database
                                    $rsConferences = rsSelect(array("conference_id", "long_name"), "conference", NULL, "ORDER BY long_name");
                                    if (is_string($rsConferences)) {
                                        echo $rsConferences . "ERROR CODE: 0" . __LINE__;
                                        exit();
                                    }
// putting each conference name in the drop down list and in a new line
                                    while ($row = mysql_fetch_assoc($rsConferences)) {
                                        echo "<option value='{$row['conference_id']}'>" . $row["long_name"] . "</option>";
                                    }
                                    ?>
                                </optgroup>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td><b><?php echo $lang['place']; ?></b> </td>
                        <td>
                            <select id="place">
                                <optgroup label="Countries">
                                    <?php
                                    $rsCountry = rsSelect("*", "country");
                                    if (is_string($rsCountry))
                                        echo $rsCountry;
                                    else {
                                        while ($row = mysql_fetch_assoc($rsCountry)) {
                                            echo "<option value='{$row['country_id']}'>" . $row['country_name'] . "</option>";
                                        }
                                    }
                                    ?>
                                </optgroup>
                            </select>
                        </td>
                    </tr>
                </table><div class="navigation"><button title="Next" class="next" id="gs"></button></div></div>
            <h3 id="deadlines"><a href="#">Deadlines</a></h3>
            <div>
                <table>
                    <tr>
                        <th style="background-color: #003366; color: white;" colspan="10"><b><?php echo $lang['submission_deadline']; ?></b></th>
                    </tr>
                    <tr>
                        <!-- created a checkbox for short paper  and gave it an id in order to use it in the above script -->
                        <td> <b><?php echo $lang['s_paper']; ?></b></label></td>
                        <td> <input type="text" size="26" id="shortpapersubmissiondate" /><label id="short_paper_label" class="error" style="color:red;"></label></td>
                    </tr>
                    <tr>
                        <!-- created a check box for long paper and gave it an id in order to use it in the above script -->
                        <td> <b><?php echo $lang['l_paper']; ?></b></label></td>
                        <td> <input type="text" size="26" id="longpapersubmissiondate" /><label id="long_paper_label" class="error" style="color:red;"></label></td>
                    </tr>
                    <tr>
                        <!-- created a check box for Image and gave it an id in order to use it in the above script -->
                        <td><b><?php echo $lang['image']; ?></b></label></td>
                        <td><input type="text" size="26" id="imagesubmissiondate" /><label id="image_label" class="error" style="color:red;"></label></td>
                    </tr>
                    <tr>
                        <!-- created a check box for video and gave it an id in order to use it in the above script -->
                        <td><b><?php echo $lang['video']; ?></b></label></td>
                        <td> <input type="text" size="26" id="videosubmissiondate" /><label id="video_label" class="error" style="color:red;"></label></td>
                    </tr>
                    <tr>
                        <!-- created a check box for poster and gave it an id in order to use it in the above script -->
                        <td> <b><?php echo $lang['poster']; ?></b></label></td>
                        <td> <input type="text" size="26" id="postersubmissiondate" /><label id="poster_label" class="error" style="color:red;"></label></td>
                    </tr>
                </table><div class="navigation"><button title="previous" id="prev-deadlines" class="previous"></button>
                    <button title="Next" class="next" id="dl"></button></div></div>
            <!-- created a table in order to help the user  to choose the required paper types that his conference will support while providing him with an area to set the date -->
            <h3 id="reviewprocess"><a href="#">Review Process</a></h3>
            <div>
                <table>
                    <tr>
                        <th style="background-color: #003366; color: white;" colspan="10"><b><?php echo $lang['review_deadline']; ?></b></th>
                    </tr>
                    <tr>
                        <td><b><?php echo $lang['review_Edate']; ?></b></td>
                        <td><input type="text" size="26" id="review_end_date" /><label id="review_end_label" class="error" style="color:red;"></label></td>
                    </tr>
                    <tr>
                        <th style="background-color: #003366; color: white;" colspan="10"><b><?php echo $lang['rebutal_deadline']; ?></b></th>
                    </tr>
                    <tr>
                        <td><label for="rebuttal_check" id="rebuttal_date_label"><?php echo $lang['rebuatalD']; ?></label></td>
                        <td><input type="text" size="26" id="rebuttal_date" /></td>
                    </tr>
                    <!-- created a table with no borders and inserted the 3 types of committees in it so the member can choose one -->
                    <tr>
                        <th style="background-color: #003366; color: white;" colspan="10"><b><?php echo $lang['committee']; ?></b></th>
                    </tr>
                    <tr>
                        <!-- created a check box for committee1  and gave it an id in order to use it in the above script -->
                        <td> <input type="checkbox" name="committee1" id="committe1checkbox"/><label for="committe1checkbox"><b><?php echo $lang['paper_committee']; ?></b></label></td>
                    </tr>
                    <tr>
                        <!-- created a check box for committee2  and gave it an id in order to use it in the above script -->
                        <td> <input type="checkbox" name="committee2" id="committe2checkbox"/><label for="committe2checkbox"><b><?php echo $lang['quality_committee']; ?></b></label></td>
                    </tr>
                    <tr>
                        <!-- created a check box for committee3  and gave it an id in order to use it in the above script -->
                        <td> <input type="checkbox" name="committee3" id="committe3checkbox" /><label for="committe3checkbox"><b><?php echo $lang['category_committee']; ?></b></label></td>
                    </tr>
                    <tr>
                        <!-- created a check box for custom committee  and gave it an id in order to use it-->
                        <td><input type="checkbox" name="custom_committee" id="custom_committee"/><label for="custom_committee"><b><?php echo $lang['custom_committee']; ?></b></label><input disabled="disabled" type="text" id="custom_text" name="custom_text" value=""/></td>
                    </tr>
                </table><div class="navigation"><button title="Previous" id="prev-reviewprocess" class="previous"></button></div>
                                   <p align="center"><button class="padding" id="Submitbutton"><b>Finish</b></button></p>
                </div><br/>
            <!-- created a submit button and gave it an id so i can use it in the script above -->
    </body>
</html>
